package Test;

import com.mysql.cj.Session;
import com.pojo.Customer;
import com.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import javax.swing.*;
import java.util.List;

public class CustomerTest {
    @Test
    public void findCustomerByNameAndjobeTest() {
        SqlSession session = MyBatisUtils.getSqlSession();
        Customer customer = new Customer();
        customer.setUsername("jack");
        customer.setJobs("teacher");
        List<Customer> customers = session.selectList("com.mapper.CustomerMapper.findCustomerByNameAndJobs", customer);
        for (Customer customer1 : customers) {
            System.out.println(customer1);
        }
        session.close();
    }
    @Test
    public void updateCustomerBySetTest (){
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        Customer customer = new Customer();
        customer.setId(3);
        customer.setPhone("13311111234");
        int row = sqlSession.update("com.itheima.mapper.CustomerMapper.updateCustomerBySet", customer);
        if (row > 0) {
            System.out.println("您成功修改了"+row+"条数据！");
        }else {
            System.out.println("执行修改操作失败！！！");
        }
        sqlSession.commit();
        sqlSession.close();
    }
    @Test
    public void findByArrayTest() {
        SqlSession session = MyBatisUtils.getSqlSession();
        Integer[] roleIds = {2,3};
       List<Customer> Customer  = session.selectList("com.mapper.CustomerMapper.findByArray",roleIds );
       for (Customer customer : Customer) {
           System.out.println(customer);
       }
       session.commit();
       session.close();
    }

}
